package com.xxx.netty.inoutbound;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * 自定义Byte转换成Long解码器
 */
@Slf4j
public class MyByteToLongDecoder extends ByteToMessageDecoder {

    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        log.info("MyByteToLongDecoder.decode()被调用.");
        if(in.readableBytes() >= 8) { // long类型占8个byte
            out.add(in.readLong());
        }
    }
}
